

use "Study 1 Britain.dta"



gen ideol_strength = (Q6_a + Q6_b + Q6_c)/30
recode ideol_strength (0/0.5 = 1 "weak") (0.51/1 = 2 "strong"), into(weak_vs_strong)

**Mapping Norms

*Calculate (Dis)approve
forval k = 1/22 {
gen Q2_`k'_diss = 1 if Q2_`k'<5
recode Q2_`k'_diss (.=0)

gen Q2_`k'_appr = 1 if Q2_`k'>5
recode Q2_`k'_appr (.=0)
}

*Calculate mass approve and disapprove
gen Left_diss = .
gen Left_diss_se = .
gen Left_appr = .
gen Left_appr_se = .
gen Right_diss = .
gen Right_diss_se = .
gen Right_appr = .
gen Right_appr_se = .
gen Left_diss_error = .  
gen Left_appr_error = .  
gen Right_diss_error = . 
gen Right_appr_error = .


*Weak
forval k = 1/22 {
mean Q2_`k'_diss if LC_ideology == 1 & ideol_strength<=0.5
matrix T = r(table)
replace Left_diss = T[1,1] in `k'
replace Left_diss_se = T[2,1] in `k'

mean Q2_`k'_appr if LC_ideology == 1 & ideol_strength<=0.5
matrix T = r(table)
replace Left_appr = T[1,1] in `k'
replace Left_appr_se = T[2,1] in `k'


mean Q2_`k'_diss if LC_ideology == 2 & ideol_strength<=0.5
matrix T = r(table)
replace Right_diss = T[1,1] in `k'
replace Right_diss_se = T[2,1] in `k'

mean Q2_`k'_appr if LC_ideology == 2 & ideol_strength<=0.5
matrix T = r(table)
replace Right_appr = T[1,1] in `k'
replace Right_appr_se = T[2,1] in `k'
}

replace Left_diss_error = 1.96*Left_diss_se

replace Left_appr_error = 1.96*Left_appr_se

replace Right_diss_error = 1.96*Right_diss_se

replace Right_appr_error = 1.96*Right_appr_se

egen right_W = rowmax(Right_appr Right_diss)
replace right_W = Right_diss in 6 
replace right_W = Right_appr in 18 
replace right_W = -right_W if Right_diss>Right_appr
replace right_W = -right_W in 6  
replace right_W = -right_W in 18 
gen right_W_error = Right_diss_error if Right_diss>Left_appr
replace right_W_error = Right_appr_error if Right_diss<Left_appr
replace right_W_error = Right_diss_error in 6 
replace right_W_error = Right_appr_error in 18 

egen left_W = rowmax(Left_appr Left_diss)
replace left_W = -left_W if Left_diss>Left_appr
gen left_W_error = Left_diss_error if Left_diss>Left_appr
replace left_W_error = Left_appr_error if Left_diss<Left_appr

*Strong
forval k = 1/22 {
mean Q2_`k'_diss if LC_ideology == 1 & ideol_strength>0.5
matrix T = r(table)
replace Left_diss = T[1,1] in `k'
replace Left_diss_se = T[2,1] in `k'

mean Q2_`k'_appr if LC_ideology == 1 & ideol_strength>0.5
matrix T = r(table)
replace Left_appr = T[1,1] in `k'
replace Left_appr_se = T[2,1] in `k'


mean Q2_`k'_diss if LC_ideology == 2 & ideol_strength>0.5
matrix T = r(table)
replace Right_diss = T[1,1] in `k'
replace Right_diss_se = T[2,1] in `k'

mean Q2_`k'_appr if LC_ideology == 2 & ideol_strength>0.5
matrix T = r(table)
replace Right_appr = T[1,1] in `k'
replace Right_appr_se = T[2,1] in `k'
}

replace Left_diss_error = 1.96*Left_diss_se

replace Left_appr_error = 1.96*Left_appr_se

replace Right_diss_error = 1.96*Right_diss_se

replace Right_appr_error = 1.96*Right_appr_se


egen right_S = rowmax(Right_appr Right_diss)
replace right_S = -right_S if Right_diss>Right_appr
gen right_S_error = Right_diss_error if Right_diss>Left_appr
replace right_S_error = Right_appr_error if Right_diss<Left_appr

egen left_S = rowmax(Left_appr Left_diss)
replace left_S = -left_S if Left_diss>Left_appr
gen left_S_error = Left_diss_error if Left_diss>Left_appr
replace left_S_error = Left_appr_error if Left_diss<Left_appr


*Calculate IQR

gen Left_median = .
gen Left_P25 = .
gen Left_P75 = .
gen Left_IQR = .

gen Right_median = .
gen Right_P25 = .
gen Right_P75 = .
gen Right_IQR = .

forval k = 1/22 {
sum Q2_`k' if LC_ideology == 1, d
replace Left_median = r(p50) in `k'
replace Left_P25 = r(p25) in `k'
replace Left_P75 = r(p75) in `k'
}

replace Left_IQR = Left_P75 - Left_P25


forval k = 1/22 {
sum Q2_`k' if LC_ideology == 2, d
replace Right_median = r(p50) in `k'
replace Right_P25 = r(p25) in `k'
replace Right_P75 = r(p75) in `k'
}

replace Right_IQR = Right_P75 - Right_P25


*Compare weak to strong
gen Left_diss_pvalue = .
gen Left_appr_pvalue = .
gen Right_diss_pvalue = .
gen Right_appr_pvalue = .


forval k = 1/22 {
ttest Q2_`k'_diss if LC_ideology == 1, by(weak_vs_strong) 
replace Left_diss_pvalue = r(p) in `k'

ttest Q2_`k'_appr if LC_ideology == 1, by(weak_vs_strong) 
replace Left_appr_pvalue = r(p) in `k'

ttest Q2_`k'_diss if LC_ideology == 2, by(weak_vs_strong) 
replace Right_diss_pvalue = r(p) in `k'

ttest Q2_`k'_appr if  LC_ideology== 2, by(weak_vs_strong) 
replace Right_appr_pvalue = r(p) in `k'
}

gen left_pvalue = Left_diss_pvalue if Left_diss>Left_appr
replace left_pvalue = Left_appr_pvalue if Left_diss<Left_appr

gen right_pvalue = Right_diss_pvalue if Right_diss>Left_appr
replace right_pvalue = Right_appr_pvalue if Right_diss<Left_appr

*******************************
*  Results files for Figure 2 *
*******************************

save "Study 1 Britain Appendix.dta", replace

keep issue right_W right_W_error left_W left_W_error right_S right_S_error left_S left_S_error Left_IQR Right_IQR left_pvalue right_pvalue

save "Study 1 Britain results.dta", replace

drop left_W left_W_error left_S left_S_error Left_IQR left_pvalue

sort right_S

save "Study 1 Britain results right.dta", replace

use "Study 1 Britain results.dta"

drop  right_W right_W_error right_S right_S_error Right_IQR right_pvalue

sort left_S

save "Study 1 Britain results left.dta", replace


**********************
*     Appendix 1     *
**********************
use "BES subset 1.dta", clear
recode leftRightW1 (0/4 = 1 "Left") (5 = 3 "Centre") (6/10 = 2 "Right") (9999 = 4 "DK"), into(LR1) 

recode leftRightW8 (0/4 = 1 "Left") (5 = 3 "Centre") (6/10 = 2 "Right") (9999 = 4 "DK"), into(LR8) 

tab LR1 LR8, row

**********************
*     Appendix 2     *
**********************
use "BES subset 2.dta", clear
gen affective_ideol = 0 if e01>6 & e01<=10
replace affective_ideol =1 if e01>=1 & e01<5
label define lr_label2 1 "Left" 0 "Right"
label values  affective_ideol lr_label2
label variable affective_ideol "Ideological ID"

recode g01_1 (-1=.), into(cut_vs_spend)
tab cut_vs_spend affective_ideol, col nofreq
twoway (histogram cut_vs_spend  if affective_ideol == 0, lcolor(none) percent  bin(10)) (histogram cut_vs_spend if affective_ideol == 1, fcolor(none) lcolor(black) percent  bin(11)), ytitle(Percent Respondents) xtitle(Tax and Spend) legend(order(1 "Right ID" 2 "Left SID" )) 
graph save Graph "Figure A1b.gph"

recode l09 (-1=.) (0=10) (1=9) (2=8) (3=7) (4=6) (5=5) (6=4) (7=3) (8=2) (9=1) (10=0), into(income_equality) 
tab income_equality affective_ideol, col nofreq
twoway (histogram income_equality if affective_ideol == 0, lcolor(none) percent  bin(10)) (histogram income_equality if affective_ideol == 1, fcolor(none) lcolor(black) percent  bin(11)), ytitle(Percent Respondents) xtitle(Persue Income Unequality) legend(order(1 "Right ID" 2 "Left SID" )) 
graph save Graph "Figure A1a.gph"

use "UK - social conservatism.dta", clear
graph bar if Ideol_id==0, over(Cindex3) title("% Social Conservative Responses (Right)") ytitle("Percent") 
graph save Graph "Figure A1c.gph"
graph bar if Ideol_id==1, over(Cindex3) title("% Social Conservative Responses (Left)") ytitle("Percent") 
graph save Graph "Figure A1d.gph"

**********************
*     Appendix 6     *
**********************
*Distribution of Normatively Correct Responses 
use "Study 1 Britain Appendix.dta", clear
gen ID_strength_bin = 0 
replace ID_strength_bin = 1 if ideol_strength >0.5

gen Con_correct = (Q2_1_appr + Q2_3_appr  + Q2_4_appr + Q2_5_diss + Q2_6_diss + Q2_8_appr + Q2_9_diss + Q2_10_appr + Q2_11_appr + Q2_12_diss + Q2_13_appr + Q2_15_appr + Q2_16_appr + Q2_17_appr + Q2_19_diss  + Q2_20_appr + Q2_21_appr + Q2_22_appr)/18 if LC_ideology == 2  
gen Lib_correct = (Q2_1_diss + Q2_2_appr  + Q2_4_appr + Q2_5_diss + Q2_6_appr + Q2_7_appr + Q2_8_diss + Q2_9_diss + Q2_10_appr + Q2_11_diss + Q2_12_appr + Q2_13_appr + Q2_14_appr + Q2_15_appr + Q2_16_appr + Q2_17_appr + Q2_18_appr + Q2_19_appr + Q2_20_appr + Q2_21_appr + Q2_22_diss)/21  if LC_ideology == 1 


twoway (histogram Con_correct if ID_strength_bin == 0, lcolor(none) percent  bin(10)) (histogram Con_correct if ID_strength_bin == 1, fcolor(none) lcolor(black) percent  bin(10)), ytitle(Percent of Right-wing Respondents) xtitle(Proportion Correct) legend(order(1 "Weak SID" 2 "Strong SID" )) 
graph save Graph "Figure A3b.gph"
twoway (histogram Lib_correct if ID_strength_bin == 0, lcolor(none) percent  bin(10)) (histogram Lib_correct if ID_strength_bin == 1, fcolor(none) lcolor(black) percent  bin(10)), ytitle(Percent of Left-wing Respondents) xtitle(Proportion Correct) legend(order(1 "Weak SID" 2 "Strong SID" )) 
graph save Graph "Figure A3a.gph"

*Factor analysis
factor Q2_1-Q2_22 if LC_ideology==2
factor Q2_1-Q2_22 if LC_ideology== 2, factor(4)
rotate
